<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>

<div style="display: none;" id="add">
    <form class="layui-form layui-form-pane" action="">
        <input type="hidden" name="goodsIssueTypeId" id="goodsIssueTypeId" />
        <div class="layui-inline">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input name="goodsIssueTypeName" id="goodsIssueTypeName" value=""  class="layui-input" lay-verify="required" type="text">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-inline">
                <input name="goodsIssueTypeNo" id="goodsIssueTypeNo" value=""  class="layui-input" lay-verify="required" type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>




<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">物品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goodsIssueTypeNames" class="layui-input" id="goodsIssueTypeNames">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn"  lay-submit lay-filter=""> <i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="employeeTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/system/selectGoodsIssueType',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                {field: 'goodsIssueTypeId',  title: 'ID'},
                {field: 'goodsIssueTypeName', title: '物品名称'},
                {field: 'goodsIssueTypeNo', title: '物品编号'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });

        // 监听搜索操作

        /**
         * toolbar监听事件
         */
        table.on('toolbar(employeeTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data)
            if (obj.event === 'add') {  // 监听添加操作
                layer.open({
                    type : 1,
                    content : $('#add')
                });
            }
        });


        table.on('tool(employeeTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data)
            if (obj.event === 'edit') {
                var goodsIssueTypeId = data.goodsIssueTypeId
                var goodsIssueTypeName=data.goodsIssueTypeName;
                var goodsIssueTypeNo=data.goodsIssueTypeNo;
                $("#goodsIssueTypeId").val(goodsIssueTypeId);
                $("#goodsIssueTypeName").val(goodsIssueTypeName);
                $("#goodsIssueTypeNo").val(goodsIssueTypeNo);
                layer.open({
                    type : 1,
                    content : $('#add')
                });
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url:"/admin/system/deleteGoodsIssueType",
                        type:"get",
                        data:{
                            goodsIssueTypeId:data.goodsIssueTypeId
                        },
                        dataType:"text",
                        success:function(data){
                            table.reload('currentTableId', {
                                url:"/admin/system/selectGoodsIssueType",
                                type:"post"
                            });
                        }
                    })
                    obj.del();
                    layer.close(index);
                });
            }
        });

        //监听表单提交事件
        form.on('submit(demo1)', function(data){
            var url = "";
            if ($("input[name='goodsIssueTypeId']").val().trim() == ""){
                url = '/admin/system/insertGoodsIssueType';
            }else{
                url = '/admin/system/updateGoodsIssueType';
            }
            //刷新
            $.ajax({
                url:url,
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if (res.code == 200){
                        layer.msg(res.message+",即将刷新",function () {
                            //刷新表格
                            table.reload('currentTableId', {
                                url: '/admin/system/selectGoodsIssueType'
                            });
                        });
                    }else{
                        layer.msg(res.message)
                    }
                }
            })
        });

    });
</script>

</body>
</html>
